//
//  EXT+UIBarButtonItem.swift
//  CZVVeiBo
//
//  Created by smile on 2017/7/29.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    convenience init(title: String?, imgName: String?, target: Any?, action: Selector){
        let btn1 = UIButton()
        btn1.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        // 如果有图片
        if let i = imgName {
            btn1.setImage(UIImage(named:i), for: UIControlState.normal)
            btn1.setImage(UIImage(named:"\(i)_highlighted"), for: UIControlState.highlighted)
        }
        // 如果有title
        if let t = title {
            btn1.setTitle(t, for: UIControlState.normal)
            btn1.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
            btn1.setTitleColor(CZAPPThemeColor, for: UIControlState.highlighted)
            btn1.setTitleColor(UIColor.blue, for: UIControlState.disabled)
            btn1.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        }
        btn1.sizeToFit()
        self.init(customView: btn1)
    }
}

